/*
Librerias para el builder maintenance!
v2.0
*/
var MAINTENANCE_TABLE="listado";
var appCallbacks=new Array();

jQuery(document.body).ready(function(){
    jQuery(":button").button();
    
});

function addFunc(f){   
    appCallbacks.push(f);
}


function isNumber(num) {
    return (typeof num == 'string' || typeof num == 'number') && !isNaN(num - 0) && num !== '';
}

function setDelMode(){
    if(confirm("Esta seguro de eliminar el registro?")){
        $("#oper").val("del");
        sendFormData(false);
    }
}

function setNewMode(){
    $(document.forms[0]).clearForm();
    $("#oper").val("add");
    $.each(appCallbacks,function(c,v){
        if(v){
            v()
        }
    });
}

function sendFormData(ask,form){
    if(ask){
        if(!confirm('Esta seguro de guardar los datos modificados?')){
            return;
        }
    }    
    if(!form){
        form=$(document.forms[0]);   
    }
    var options = {            
        success:function(){
            setNewMode();
            jQuery("#_grid_").jqGrid().trigger("reloadGrid");
        }
    }
    $(form).ajaxSubmit(options); 
/*$(form).validate({
        submitHandler:function(f){                
                           
        }
    });*/
}

function calcEdad($inFecha,$inEdad){
    setEdad(jQuery("#"+$inFecha),jQuery("#"+$inEdad))
}

function setEdad(fldO,fldD){
    var curr = new Date();
    var dob = parseDate(jQuery(fldO).val());
    var edad= curr.getFullYear() - dob.getFullYear();
    jQuery(fldD).val(edad);
}
function parseDate(stringdate){
    var sep='/';
    var dia= new String(stringdate.substring(0,stringdate.indexOf(sep)))
    var mes= new String(stringdate.substring(stringdate.indexOf(sep)+1,stringdate.lastIndexOf(sep)))
    var ano= new String(stringdate.substring(stringdate.lastIndexOf(sep)+1,stringdate.length))
    var date=new Date();
    date.setFullYear(ano,mes,dia);
		
    return date;
}

function fntOpenDialogCargando() {
    (function($){
        $("#dialog-cargando").dialog({
            resizable: false,
            modal: true,
            closeOnEscape: false,
            open: function() {
                objImg = $("#img-cargando");
                objDialog = $("#dialog-cargando");
                intDialogWidth = objImg.outerWidth(false);
                intDialogHeight = objImg.outerHeight(false);
                $(".ui-dialog-titlebar").hide();
                if( $.browser.msie ) {
                    objDialog.dialog( "option", "width", intDialogWidth );
                    objDialog.dialog( "option", "height", intDialogHeight );
                }
                else {
                    intDialogHeight += 15;
                    objDialog.dialog( "option", "width", intDialogWidth );
                    objDialog.dialog( "option", "height", intDialogHeight );
                }

            }
        });
    })(jQuery);
}

/**
 *
 **/
function fntCloseDialogCargando() {
    $("#dialog-cargando").dialog( "close" );
}

/**
 * 
 */
function doSubmit(param){
    var form=document.forms[0];
    var url=form.action;
    form.action=url+"?"+param;
    form.submit();
}